import { ipcMain } from 'electron'
import { addFrequency, updateFrequency, getUserById, getAnserById } from '../service/frequency'

/*
  frequency-add 增加场次
  frequency-update 更新场次
  frequency-get-user-by-id 根据场次获取用户信息
  frequency-get-answer-by-id 根据场次id获取用户答题记录
*/

const frequencyController = () => {
  ipcMain.handle('frequency-add', async (event, data) => {
    try {
      const res = await addFrequency(data)
      return res
    } catch (error) {
      return []
    }
  })
  ipcMain.handle('frequency-update', async (event, data) => {
    try {
      const res = await updateFrequency(data)
      return res
    } catch (error) {
      return []
    }
  })
  ipcMain.handle('frequency-get-user-by-id', async (event, id) => {
    try {
      const res = await getUserById(id)
      return res
    } catch (error) {
      return []
    }
  })

  ipcMain.handle('frequency-get-answer-by-id', async (event, id) => {
    try {
      const res = await getAnserById(id)
      return res
    } catch (error) {
      return []
    }
  })
}

export default frequencyController
